<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
class Staff_model extends CI_Model{
    public function __construct() {
        parent::__construct();
        $this->load->database();
    }
    public function getStaff()
    {
        $query=$this->db->get('Staff');
        return $query;
    }
    public function getStaffLimited($per_page,$start_row)
    {
        $query=$this->db->get('Staff',$per_page,$start_row);
        return $query->result();
    }
    public function getStaffForeigners()
    {
        $this->db->where('Foreigners',1);
        $query=$this->db->get('Staff');
        return $query;
    }
    public function getStaffLimitedForeigners($per_page,$start_row)
    {
        $this->db->where('Foreigners',1);
        $query=$this->db->get('Staff',$per_page,$start_row);
        return $query->result();
    }
    public function getStaffByID($Staff_ID)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $query=$this->db->get('Staff');
        return $query;
    }
    public function insertNext($Staff_ID,$FullName,$FirstName,$LastName,$DOB,$POB,
            $Marital,$Gender,$PersonalTaxCode,$NumberOfDependent,$ID_Number,$DOI,$POI,$HomePhone,$CellPhone,

            $PersonalEmail1,$PersonalEmail2,$CompanyEmail,$Foreigners)

    {
        $insertnext=array(
            'Staff_ID'=>$Staff_ID,
            'FullName'=>$FullName,
            'FirstName'=>$FirstName,
            'LastName'=>$LastName,
            'DOB'=>$DOB,
            'POB'=>$POB,
            'MaristalStatus'=>$Marital,
            'Gender'=>$Gender,
            'PersonalTaxCode'=>$PersonalTaxCode,
            'NumberOfDependent'=>$NumberOfDependent,
            'ID_Number'=>$ID_Number,
            'DOI'=>$DOI,
            'POI'=>$POI,
            'HomePhone'=>$HomePhone,
            'CellPhone'=>$CellPhone,
            'PersonalEmail1'=>$PersonalEmail1,
            'PersonalEmail2'=>$PersonalEmail2,
            'CompanyEmail'=>$CompanyEmail,
            'Foreigners'=>$Foreigners
            
        );
        $insert_next=$this->db->insert('Staff',$insertnext);
        return $insert_next;
    }
    public function insertStaff($Staff_ID,$PANSWD,$PACity,
            $PACountry,$CVSumup,$CANSWD,$CACity,
            $CACountry,$VehicleNo,$VehicleType,$VehicleColor)
    {
        $insertstaff=array(
            'PA_NSWD'=>$PANSWD,
            'PA_City'=>$PACity,
            'PA_Country'=>$PACountry,
            'CV_Sumup'=>$CVSumup,
            'CA_NSWD'=>$CANSWD,
            'CA_City'=>$CACity,
            'CA_Country'=>$CACountry,
            'VehicleNo'=>$VehicleNo,
            'VehicleType'=>$VehicleType,
            'VehicleColour'=>$VehicleColor

        );
        $insert_staff=$this->db->update('Staff',$insertstaff,array('Staff_ID' => $Staff_ID));
        return $insert_staff;
    }
    public function deleteCVByCVID($CV_ID)
    {
        $this->db->where('CV_ID',$CV_ID);
        $this->db->delete('CV');
    }
    public function deleteInterviewByCVID($CV_ID)
    {
        $this->db->where('CV_ID',$CV_ID);
        $this->db->delete('Interview');
    }
    public function checkStaffExist($Staff_ID)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $query=$this->db->get('Staff');
        return $query;
    }
    public function checkIDNumberExist($ID_Number)
    {
        $this->db->where('ID_Number',$ID_Number);
        $query=$this->db->get('Staff');
        return $query;
    }
    public function editStaff($Staff_ID,$FullName,$FirstName,$LastName,$DOB,$POB,
            $Marital,$Gender,$PersonalTaxCode,$NumberOfDependent,$ID_Number,$DOI,$POI,$HomePhone,$CellPhone,
            $PersonalEmail1,$PersonalEmail2,$CompanyEmail,$PANSWD,$PACity,
            $PACountry,$CVSumup,$CANSWD,$CACity,
            $CACountry,$VehicleNo,$VehicleType,$VehicleColor)
    {
        $editstaff=array(
            'FullName'=>$FullName,
            'FirstName'=>$FirstName,
            'LastName'=>$LastName,
            'DOB'=>$DOB,
            'POB'=>$POB,
            'MaristalStatus'=>$Marital,
            'Gender'=>$Gender,
            'PersonalTaxCode'=>$PersonalTaxCode,
            'NumberOfDependent'=>$NumberOfDependent,
            'ID_Number'=>$ID_Number,
            'DOI'=>$DOI,
            'POI'=>$POI,
            'HomePhone'=>$HomePhone,
            'CellPhone'=>$CellPhone,
            'PersonalEmail1'=>$PersonalEmail1,
            'PersonalEmail2'=>$PersonalEmail2,
            'CompanyEmail'=>$CompanyEmail,
            'PA_NSWD'=>$PANSWD,
            'PA_City'=>$PACity,
            'PA_Country'=>$PACountry,
            'CV_Sumup'=>$CVSumup,
            'CA_NSWD'=>$CANSWD,
            'CA_City'=>$CACity,
            'CA_Country'=>$CACountry,
            'VehicleNo'=>$VehicleNo,
            'VehicleType'=>$VehicleType,
            'VehicleColour'=>$VehicleColor,
            
           
        );
        $edit_staff=$this->db->update('Staff',$editstaff,array('Staff_ID' => $Staff_ID));
        return $edit_staff;
    }
    function insertFamily($Staff_ID,$Relative,$FullName,$Gender,$DOB)
    {
        $insert_family=array(
            'Staff_ID'=>$Staff_ID,
            'Relative'=>$Relative,
            'FullName'=>$FullName,
            'Gender'=>$Gender,
            'DOB'=>$DOB
        );
        $insertfamily=$this->db->insert('Family',$insert_family);
        return $insertfamily;
    }
    function getFamilyByStaffID($Staff_ID)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $query=$this->db->get('Family');
        return $query;
    }
    function getFamilyByStaffIDLimited($Staff_ID,$per_page,$start_row)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $query=$this->db->get('Family',$per_page,$start_row);
        return $query;
    }
    public function getFullNameByStaffID($Staff_ID)
    {
        $sql="select FullName from Staff where Staff_ID=$Staff_ID";
        $query=$this->db->query($sql);
        return $query;
    }
    public function getFullNameByIDNumber($ID_Number)
    {
        $sql="select FullName from Staff where ID_Number=$ID_Number";
        $query=$this->db->query($sql);
        return $query;
    }
    public function deleteStaff($Staff_ID)
    {
        
      
        $tables=array('Bonus','Discipline','Family','ProjectStaff','StaffTraining','WorkPurpose','Staff');
        $this->db->where('Staff_ID',$Staff_ID);
        $this->db->delete($tables);
 
        
    }
    public function getListExperienceStaff($Staff_ID)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $query=$this->db->get('Experience');
        return $query;
    }
    public function getListExperienceStaffLimited($Staff_ID,$per_page,$start_row)
    {
        
        $this->db->where('Staff_ID',$Staff_ID);
        //$this->db->limit($per_page,$start_row);
        $query=$this->db->get('Experience',$per_page,$start_row);
        return $query;
    }
    public function checkExperienceStaff($Staff_ID,$Education,$PreviousPosition,$Company,$Industry,$Year)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $this->db->where('Education',$Education);
        $this->db->where('PreviousPosition',$PreviousPosition);
        $this->db->where('Company',$Company);
        $this->db->where('Industry',$Industry);
        $this->db->where('Year',$Year);
        $query=$this->db->get('Experience');
        return $query;
        
    }
    public function insertExperienceStaff($Staff_ID,$Education,$PreviousPosition,$Company,$Industry,$Year)
    {
        $insert_experience_staff=array(
            'Staff_ID'=>$Staff_ID,
            'Education'=>$Education,
            'PreviousPosition'=>$PreviousPosition,
            'Company'=>$Company,
            'Industry'=>$Industry,
            'Year'=>$Year
        );
        $insertexperiencestaff=$this->db->insert('Experience',$insert_experience_staff);
        return $insertexperiencestaff;
    }
    public function updateExperienceStaff($Experience_ID,$Education,$PreviousPosition,$Company,$Industry,$Year)
    {
        $update_experience_staff=array(
            'Education'=>$Education,
            'PreviousPosition'=>$PreviousPosition,
            'Company'=>$Company,
            'Industry'=>$Industry,
            'Year'=>$Year
        );
        $updateexperiencestaff=$this->db->update('Experience',$update_experience_staff,array('Experience_ID'=>$Experience_ID));
        return $updateexperiencestaff;
    }
    public function deleteExperienceStaff($Experience_ID)
    {
        $this->db->where('Experience_ID',$Experience_ID);
        $this->db->delete('Experience');
    }
    public function addViPass($ID_Number,$Type,$Nationality,$NumberVisa,$VisaDateStart,$VisaDateEnd)
    {
        $add_visa=array(
          'PassPort_ID'=>$ID_Number,
            'Type'=>$Type,
            'Nationality'=>$Nationality,
            'NumberVisa'=>$NumberVisa,
            'VisaDateStart'=>$VisaDateStart,
            'VisaDateEnd'=>$VisaDateEnd
        );
        $addvisa=$this->db->insert('PassVi',$add_visa);
        return $addvisa;
    }
    public function getPassViByIDNumber($ID_Number)
    {
        $this->db->where('PassPort_ID',$ID_Number);
        $query=$this->db->get('PassVi');
        return $query;
    }
    public function updatePassVi($ID_Number,$Type,$Nationality,$NumberVisa,$VisaDateStart,$VisaDateEnd,$VisaDateUpdate)
    {
        $update_visa=array(
            'Type'=>$Type,
            'Nationality'=>$Nationality,
            'NumberVisa'=>$NumberVisa,
            'VisaDateStart'=>$VisaDateStart,
            'VisaDateEnd'=>$VisaDateEnd,
            'VisaDateUpdate'=>$VisaDateUpdate
        );
        $updatevisa=$this->db->update('PassVi',$update_visa,array('PassPort_ID'=>$ID_Number));
        return $updatevisa;
    }
    public function getFamilyByFamilyID($Family_ID)
    {
        $this->db->where('Family_ID',$Family_ID);
        $query=$this->db->get('Family');
        return $query;
    }
    public function deleteFamily($Family_ID)
    {
        $this->db->where('Family_ID',$Family_ID);
        $this->db->delete('Family');
    }
    public function updateFamily($Family_ID,$Relative,$FullName,$Gender,$DOB)
    {
        $update_family=array(
          'Relative'=>$Relative,
            'FullName'=>$FullName,
            'Gender'=>$Gender,
            'DOB'=>$DOB
        );
        $updatefamily=$this->db->update('Family',$update_family,array('Family_ID'=>$Family_ID));
        return $updatefamily;
    }
    public function getExperienceByExperienceID($Experience_ID)
    {
        $this->db->where('Experience_ID',$Experience_ID);
        $query=$this->db->get('Experience');
        return $query;
    }
    public function getSalaryByStaffID($Staff_ID)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $query=$this->db->get('Salary');
        return $query;
    }
    public function getListSalaryByStaffID($Staff_ID,$FromDate,$ToDate)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        $this->db->where('FromDate',$FromDate);
        $this->db->where('ToDate',$ToDate);
        $query=$this->db->get('Salary');
        return $query;
    }
    public function getSalaryByStaffIDLimited($Staff_ID,$per_page,$start_row)
    {
        $this->db->where('Staff_ID',$Staff_ID);
        //$this->db->limit($per_page,$start_row);
        $query=$this->db->get('Salary',$per_page,$start_row);
        return $query;
    }
    
}
?>
